// 最近使用 Emoji队列
export class Queue {
  private elements: Array<number> // Emoji的索引位置

  private capacity: number // 容量

  constructor(elements: Array<number>, capacity: number) {
    this.elements = elements || []
    this.capacity = capacity || Infinity
  }

  public push(index: number) {
    if (!index) return false

    const indexIndex = this.elements.indexOf(index)
    if (indexIndex !== -1) {
      this.elements.splice(indexIndex, 1) // 移除第一个匹配的index
    }

    if (this.elements.length == this.capacity) {
      this.pop()
    }

    this.elements.unshift(index)
    return true
  }

  public pop() {
    return this.elements.pop()
  }

  public size() {
    return this.elements.length
  }

  public isEmpty() {
    return this.elements.length === 0
  }

  public clear() {
    this.elements = []
  }

  public getCapacity() {
    return this.capacity
  }

  public getElements() {
    return this.elements
  }
}
